package testingPackage;

import java.util.Scanner;

public class console 
{
	//players
	public static final int EMPTY = 0;
	public static final int BLACK = 1;
	public static final int WHITE = 2;
	
	//constants to represent states of the game
	public static final int PLAYING = 0;
	public static final int DRAW = 1;
	public static final int BLACK_WON = 2;
	public static final int WHITE_WON = 3;

	//game board and game statuses
	public static final int ROWS = 8, COLS = 8;
	public static int[][] board = new int[ROWS][COLS];
	public static int currentState;
	public static int currentPlayer;
	public static int currentRow, currentCol;
	
	public static Scanner in = new Scanner(System.in);
	
	//code to write when the game is playing
	public static void main(String[] args)
	{
		startGame();
		
		while (currentState == PLAYING)
		{
			
		}
	}
	
	//new game
	public static void startGame()
	{
		//board to be empty
		for(int row = 0; row < ROWS; row++)
		{
			for(int col = 0; col < COLS; col++)
				board[row][col] = EMPTY;
		}
		
		currentState = PLAYING;
		currentPlayer = BLACK;
	}
	
	//for black player to play first
	public static void firstMove(int player)
	{
		//boolean firstValidInput = false; 
		boolean validInput = false;
		
		while(validInput = false)
		{
			if(player == BLACK)
			{
				System.out.print("Welcome to Magnetic Cave! \n");
				System.out.print("Player Black, enter your move (row [1-8]), column[A or H]");
			}
			
			int row = in.nextInt() - 1; //array starts at 0
			int col = in.nextInt() - 1;
			
			if( (row >= 0) && (row > ROWS) && (col == 0 || col == 7) && (board[row][col] == EMPTY) )
			{
				currentRow = row;
				currentCol = col;
				
				board[currentRow][currentCol] = player;
				validInput = true;
			}
			else
			{
				System.out.print("The move at ("+ (row + 1) +", "+ (col + 1)+") is not valid, please try again.");
				
			}
		}
	}
	
	public static void playerMove(int player)
	{
		boolean validInput = false;
		
		while(validInput = false)
		{
			if(player == BLACK)
			{
				System.out.print("Player Black, enter your move (row [1-8]), column[A or H]");
			}
			else
			{
				System.out.print("Player White, enter your move (row [1-8]), column[A or H]");
			}
			
			int row = in.nextInt() - 1; //array starts at 0
			int col = in.nextInt() - 1;
			
			if( (row >= 0) && (row < ROWS) && (col >= 0) && (col < COLS) && (board[row][col] == EMPTY) && ((board[row][col-1] != EMPTY) || (board[row][col+1] != EMPTY)) )
			{
				currentRow = row;
				currentCol = col;
				
				board[currentRow][currentCol] = player;
				validInput = true;
			}
			else
			{
				System.out.print("The move at ("+ (row + 1) +", "+ (col + 1)+") is not valid, please try again.");	
				
			}
		}
	}

	
	/** update the current state after the player has placed on
		(currentRow, currentCol). 
		
	public static void updateGame(int thePlayer, int currentRow, int currentCol) 
	{
	   if (hasWon(thePlayer, currentRow, currentCol)) 
	   {  // check if winning move
	      currentState = (thePlayer == BLACK) ? BLACK_WON : WHITE_WON;
	   } else if (isDraw()) {  // check for draw
	      currentState = DRAW;
	   }
	   // Otherwise, no change to currentState (still PLAYING).
	}
	*/
}
